<?
/*
+--------------------------------------------------------------------------
|   TalkBack Ticket System
|   ========================================
|   by Oliver Hayman
|   (c) 2007 OlliesPage.net
|   ========================================
|   
|   
+---------------------------------------------------------------------------
|   > $Date: 2007-09-02 16:56:14 +0000 (Sun, 02 Sep 2007) $
|   > $Author: Oliver Hayman $
+---------------------------------------------------------------------------
|
|   > INDEX
|   > Includes configuration file, creates database connections
|   > Defines headers and footers.
|   > Date started: Tuesday 28th August 2007 (12:02)
|
+--------------------------------------------------------------------------
*/
session_start(); if(!isset($_SESSION['power']) || $_SESSION['power'] != 'Administrator') { header("location: ../../index.php"); }
include('main.php');
if(isset($_GET['op'])) {
$op = $_GET['op'];
// ---------[Amazing op Switch to handel all requests to teh page]----------------
switch($op) {

case 'showClosed':
$_SESSION['closed'] = true;
break;

case 'hideClosed':
$_SESSION['closed'] = false;
break;

default:
break;
} }
$total = 'SELECT count(*) as total FROM `messages` WHERE `Uname`=\''.$_SESSION[username].'\'';
$total = mysql_fetch_row(mysql_query($total));
$total = $total[0];
$reply = 'SELECT count(*) as total FROM `messages` WHERE `status`=2 and `Uname`=\''.$_SESSION[username].'\'';
$reply = mysql_fetch_row(mysql_query($reply));
$reply = $reply[0];
$hold = 'SELECT count(*) as total FROM `messages` WHERE `status`=1 and `Uname`=\''.$_SESSION[username].'\'';
$hold = mysql_fetch_row(mysql_query($hold));
$hold = $hold[0];
$closed = 'SELECT count(*) as total FROM `messages` WHERE `status`=0 and `Uname`=\''.$_SESSION[username].'\'';
$closed = mysql_fetch_row(mysql_query($closed));
$closed = $closed[0]; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!--<meta http-equiv="Refresh" content="60;url=index.php?<? echo $_GET['id']; ?>" />-->
<link REL="shortcut icon" HREF="favicon.ico" TYPE="image/x-icon">
<style>
.row2
{
	BACKGROUND-COLOR: #F7FAFF;
	COLOR: #000000;
    FONT-SIZE: 11px;
    FONT-FAMILY: Verdana, Arial, Helvetica;
}
.smalltext
{
    FONT-SIZE: 11px;
    COLOR: #333333;
    FONT-FAMILY: Verdana, Arial, Helvetica;
}
a.footer:link {		color: #333333; }
a.footer:visited {	color: #333333; }
a.footer:hover {	color: #333333; text-decoration: underline; }
a.footer:active {	color: #333333; }
a.footer {			text-decoration: none; }
.text
{
    FONT-SIZE: 13px;
    COLOR: #333333;
    FONT-FAMILY: Verdana, Arial, Helvetica;
}
</style>
</head>
<body>
<center><img src="images/header.jpg" /><br />
  <table width="900" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <th align="center" scope="col"><a href="talkback.php">Start A New TalkBack Session</a></th>
    </tr>
    <tr>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td rowspan="2" valign="top"><fieldset style="width: 80%; margin-top: 10px; margin-bottom: 6px; color: #267DDC; BORDER: 1px SOLID #CCCCCC; -moz-border-radius: 4px 4px 4px 4px; padding: 4px">	<table width="100%"  border="0" cellspacing="1" cellpadding="4">
	  <tr>
		<td align="left" valign="top"><span class="smalltext">Welcome <? echo $_SESSION[firstname]; ?></span></td>
	  </tr>
	  <tr>
		<td align="left" valign="top"><span class="smalltext">Today is <? echo date('d M Y, h:i A'); ?></span></td>
	  </tr>
	  <tr>
		<td align="left" valign="top"><span class="smalltext">Total Number of TalkBack sessions: <? echo $total; ?> </span></td>
	  </tr>
	  </table></fieldset></td>
          <td><fieldset style="width: 80%; margin-bottom: 6px; color: #267DDC; BORDER: 1px SOLID #CCCCCC; -moz-border-radius: 4px 4px 4px 4px; padding: 4px">
	<legend>Your Session Information</legend>
	<table width="100%"  border="0" cellspacing="1" cellpadding="4">
	  <tr>
		<td align="left" valign="top" class="row2"><span class="smalltext">TalkBack Sessions Requiring a reply:</span></td>
		<td width="30%" align="left" valign="top" style="width: 21%"><span class="smalltext"><? echo $reply; ?></span></td>
	  </tr>
	  <tr>
		<td align="left" valign="top" class="row2"><span class="smalltext">TalkBack Sessions on hold: </span></td>
		<td width="30%" align="left" valign="top" style="width: 21%"><span class="smalltext"><? echo $hold; ?></span></td>
	  </tr>
	  <tr>
		<td align="left" valign="top" class="row2"><span class="smalltext">TalkBack Sessions closed: </span></td>
		<td width="30%" align="left" valign="top" style="width: 21%"><span class="smalltext"><? echo $closed; ?></span></td>
	  </tr>
	  </table>
</fieldset></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td><p align="center">
<? if(isset($_SESSION['closed']) && $_SESSION['closed'] !='true') {
echo 'Reminder: closed sessions are automatically omitted from the  list below <a href="index.php?op=showClosed">Click Here</a> to include them'; } else {
echo 'Showing Closed sessions <a href="index.php?op=hideClosed">Click Here</a> to hide them'; } ?>
</p></td>
    </tr>
    <tr>
      <td><table align="center" width="100%" border="1">
  <tr>
    <th background="images/tablebg.gif" colspan="5" scope="col">TalkBack Sessions </th>
  </tr>
  <tr>
    <th style="background-color: #87CEEB;">Status</th>
    <th style="background-color: #87CEEB;">Replys</th>
	<th style="background-color: #87CEEB;">Message Preview</th>
	<th style="background-color: #87CEEB;">Feedback Type</th>
    <th style="background-color: #87CEEB;">Date of last activity</th>
  </tr> 
<?
if(isset($_SESSION['closed']) && $_SESSION['closed']=='true') {
$sql = 'SELECT * FROM messages WHERE `status`!=3 and `Uname`=\''.$_SESSION[username].'\';';
} else { $sql = 'SELECT * FROM messages WHERE `status`= 1 and `Uname`=\''.$_SESSION[username].'\' or `status`= 2 and `Uname`=\''.$_SESSION[username].'\''; }
$query = mysql_query($sql);
$num = mysql_num_rows($query);
if($num < 1) {
$html .=<<<EOA
  <tr>
    <td colspan="5"><span class="smalltext">No TalkBack Sessions found</span></td>
  </tr>
EOA;
} else {
while($i < $num) {
$a = mysql_fetch_array($query);
$replys = 'SELECT count(*) as total FROM replys WHERE `Uid`=\''.$a[Uid].'\';';
$replys = mysql_fetch_array(mysql_query($replys));
if($a[status] == 1) { $status = '<font color="#8BB467">On Hold</font>'; } elseif($a[status] == 2) { $status = '<font color="#FF0000">Requires Reply</font>'; } elseif($a[status] == 0) { $status = '<font color="#8A8A8A">Closed</font>'; }
if($a[Respond] == 0 && $a[status] == 1) { $status = '<font color="#FF0000">Requires Review</font>'; }
if($a[type] == 0) { $type = 'Support Request';} elseif($a[type] == 1) { $type = 'Bug Report'; } else {$type = 'Feedback';}
if($a[Respond] == 0 || ($replys < 1)) { $activ = $a['time']; } else { 
$activ = 'SELECT `replytime` FROM `replys` WHERE `Uid` = '.$a[Uid].' ORDER BY `replys` . `replytime` DESC LIMIT 0, 1;';
$activ = mysql_fetch_row(mysql_query($activ));
$activ = $activ[0]; }
$activ = date('d M Y, h:i A', strtotime($activ));
$message_preview = substr($a[Message], 0, 50);
$html .=<<<EOA
  <tr>
    <td><span class="smalltext"><a href="viewtalkback.php?id=$a[Uid]" style="text-decoration: none;">$status</a></span></td>
    <td><span class="smalltext">$replys[0]</span></td>
    <td><span class="smalltext">$message_preview...</span></td>
    <td><span class="smalltext">$type</span></td>
    <td><span class="smalltext">$activ</span></td>
  </tr>
EOA;
$i++;
} }
$html.='</table>';
echo $html
?>
  </table>
  </td>
    </tr>
  </table>
</center><br />
<? footer(); ?>
</body>
</html>